home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / printf.man < prev    next >
Encoding:
Text File  |  1990-09-24  |  10.2 KB  |  265 lines

  1.  
  2.  
  3.  
  4. PRINTF                C Library Procedures                 PRINTF
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      printf, fprintf, sprintf, vprintf, vfprintf, vsprintf,
  10.      vsnprintf - formatted output conversion
  11.  
  12. SSYYNNOOPPSSIISS
  13.      ##iinncclluuddee <<ssttddiioo..hh>>
  14.  
  15.      pprriinnttff((ffoorrmmaatt [,, arg ] ...  ))
  16.      cchhaarr **ffoorrmmaatt;;
  17.  
  18.      ffpprriinnttff((ssttrreeaamm,, ffoorrmmaatt [,, arg ] ...  ))
  19.      FFIILLEE **ssttrreeaamm;;
  20.      cchhaarr **ffoorrmmaatt;;
  21.  
  22.      cchhaarr **sspprriinnttff((ss,, ffoorrmmaatt [,, arg ] ...  ))
  23.      cchhaarr **ss,, **ffoorrmmaatt;;
  24.  
  25.      ##iinncclluuddee <<vvaarraarrggss..hh>>
  26.      vvpprriinnttff((ffoorrmmaatt,, aarrggss))
  27.      cchhaarr **ffoorrmmaatt;;
  28.      vvaa__lliisstt aarrggss;;
  29.  
  30.      vvffpprriinnttff((ssttrreeaamm,, ffoorrmmaatt,, aarrggss))
  31.      FFIILLEE **ssttrreeaamm;;
  32.      cchhaarr **ffoorrmmaatt;;
  33.      vvaa__lliisstt aarrggss;;
  34.  
  35.      cchhaarr **vvsspprriinnttff((ss,, ffoorrmmaatt,, aarrggss))
  36.      cchhaarr **ss,, **ffoorrmmaatt;;
  37.      vvaa__lliisstt aarrggss;;
  38.  
  39.      cchhaarr **vvssnnpprriinnttff((ss,, nnBByytteess,, ffoorrmmaatt,, aarrggss))
  40.      cchhaarr **ss;;
  41.      iinntt nnBByytteess;;
  42.      cchhaarr **ffoorrmmaatt;;
  43.      vvaa__lliisstt aarrggss;;
  44.  
  45. DDEESSCCRRIIPPTTIIOONN
  46.      _P_r_i_n_t_f places output on the standard output stream ssttddoouutt.
  47.      _F_p_r_i_n_t_f places output on the named output _s_t_r_e_a_m.  _S_p_r_i_n_t_f
  48.      places `output' in the string _s, followed by the character
  49.      `\0'.  Alternate forms, in which the arguments have already
  50.      been captured using the variable-length argument facilities
  51.      of _v_a_r_a_r_g_s(3), are available under the names _v_p_r_i_n_t_f,
  52.      _v_f_p_r_i_n_t_f, _v_s_p_r_i_n_t_f, and _v_s_n_p_r_i_n_t_f.  (_V_s_n_p_r_i_n_t_f is like
  53.      _v_s_p_r_i_n_t_f, except that it takes an additional argument speci-
  54.      fying the size of the character buffer _s.  It is included
  55.      for compatibility with the Carnegie Mellon CS library.)
  56.  
  57.      Each of these functions converts, formats, and prints the
  58.      arguments that come after the _f_o_r_m_a_t argument.  The _f_o_r_m_a_t
  59.      argument controls this conversion process.  It is a
  60.  
  61.  
  62.  
  63. Sprite v1.0             24 September 1990                       1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PRINTF                C Library Procedures                 PRINTF
  71.  
  72.  
  73.  
  74.      character string which contains two types of objects: plain
  75.      characters, which are simply copied to the output stream,
  76.      and conversion specifications, each of which causes conver-
  77.      sion and printing of the next successive _a_r_g.
  78.  
  79.      Each conversion specification is introduced by the character
  80.      %%.  The remainder of the conversion specification includes
  81.      in the following order
  82.  
  83.      oo++    Zero or more of the following flags:
  84.  
  85.           oo++    a `#' character specifying that the value should
  86.                be converted to an ``alternate form''.  For cc, dd,
  87.                ss, and uu, conversions, this option has no effect.
  88.                For oo conversions, the precision of the number is
  89.                increased to force the first character of the out-
  90.                put string to a zero.  For xx(XX) conversion, a
  91.                non-zero result has the string 00xx(00XX) prepended to
  92.                it.  For ee, EE, ff, gg, and GG, conversions, the
  93.                result will always contain a decimal point, even
  94.                if no digits follow the point (normally, a decimal
  95.                point only appears in the results of those conver-
  96.                sions if a digit follows the decimal point).  For
  97.                gg and GG conversions, trailing zeros are not
  98.                removed from the result as they would otherwise
  99.                be;
  100.  
  101.           oo++    a minus sign `-' which specifies _l_e_f_t _a_d_j_u_s_t_m_e_n_t
  102.                of the converted value in the indicated field;
  103.  
  104.           oo++    a `+' character specifying that there should
  105.                always be a sign placed before the number when
  106.                using signed conversions;
  107.  
  108.           oo++    a space specifying that a blank should be left
  109.                before a positive number during a signed conver-
  110.                sion.  A `+' overrides a space if both are used;
  111.  
  112.           oo++    a zero `0' character indicating that zero-padding
  113.                should be used rather than blank-padding.  A `-'
  114.                overrides a `0' if both are used;
  115.  
  116.      oo++    an optional digit string specifying a _f_i_e_l_d _w_i_d_t_h; if
  117.           the converted value has fewer characters than the field
  118.           width it will be blank-padded on the left (or right, if
  119.           the left-adjustment indicator has been given) to make
  120.           up the field width (note that a leading zero is a flag,
  121.           but an embedded zero is part of a field width);
  122.  
  123.      oo++    an optional period, followed by an optional digit
  124.           string giving a _p_r_e_c_i_s_i_o_n which specifies the number of
  125.           digits to appear after the decimal point, for e- and
  126.  
  127.  
  128.  
  129. Sprite v1.0             24 September 1990                       2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PRINTF                C Library Procedures                 PRINTF
  137.  
  138.  
  139.  
  140.           f-conversion, or the maximum number of characters to be
  141.           printed from a string; if the digit string is missing,
  142.           the precision is treated as zero;
  143.  
  144.      oo++    the character ll specifying that a following dd, ii, oo, xx,
  145.           or uu corresponds to a long integer _a_r_g, or that a fol-
  146.           lowing nn corresponds to a pointer to a long integer
  147.           _a_r_g;
  148.  
  149.      oo++    the character hh specifying that a following dd, ii, oo, xx,
  150.           or uu corresponds to a short integer _a_r_g, or that a fol-
  151.           lowing nn corresponds to a pointer to a short integer
  152.           _a_r_g;
  153.  
  154.      oo++    a character which indicates the type of conversion to
  155.           be applied.
  156.  
  157.      A field width or precision may be `*' instead of a digit
  158.      string.  In this case an integer _a_r_g supplies the field
  159.      width or precision.
  160.  
  161.      The conversion characters and their meanings are
  162.  
  163.      ddooxx  The integer _a_r_g is converted to signed decimal,
  164.           unsigned octal, or unsigned hexadecimal notation
  165.           respectively.
  166.  
  167.      ii    An alias for `d'.
  168.  
  169.      ff    The float or double _a_r_g is converted to decimal nota-
  170.           tion in the style `[--]ddd.ddd' where the number of d's
  171.           after the decimal point is equal to the precision
  172.           specification for the argument.  If the precision is
  173.           missing, 6 digits are given; if the precision is expli-
  174.           citly 0, no digits and no decimal point are printed.
  175.  
  176.      eeEE   The float or double _a_r_g is converted in the style
  177.           `[--]d..dddee+_dd' where there is one digit before the
  178.           decimal point and the number after is equal to the pre-
  179.           cision specification for the argument; when the preci-
  180.           sion is missing, 6 digits are produced.  An uppercase E
  181.           is used for `E' conversion.
  182.  
  183.      ggGG   The float or double _a_r_g is printed in style ff or in
  184.           style ee (EE) whichever gives full precision in minimum
  185.           space.
  186.  
  187.      cc    The character _a_r_g is printed.
  188.  
  189.      ss    _A_r_g is taken to be a string (character pointer) and
  190.           characters from the string are printed until a null
  191.           character or until the number of characters indicated
  192.  
  193.  
  194.  
  195. Sprite v1.0             24 September 1990                       3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PRINTF                C Library Procedures                 PRINTF
  203.  
  204.  
  205.  
  206.           by the precision specification is reached; however if
  207.           the precision is 0 or missing all characters up to a
  208.           null are printed.
  209.  
  210.      uu    The unsigned integer _a_r_g is converted to decimal and
  211.           printed (the result will be in the range 0 through MAX-
  212.           UINT, where MAXUINT equals 4294967295 on a VAX-11 and
  213.           65535 on a PDP-11).
  214.  
  215.      nn    _A_r_g is taken to be a pointer to an integer (possibly
  216.           sshhoorrtt or lloonngg) through which is stored the number of
  217.           characters written to the output stream (or string) so
  218.           far by this call to pprriinnttff (or ffpprriinnttff, etc.).
  219.  
  220.      pp    _A_r_g is taken to be a pointer to vvooiidd; it is printed in
  221.           style xx.
  222.  
  223.      %%    Print a `%'; no argument is converted.
  224.  
  225.      In no case does a non-existent or small field width cause
  226.      truncation of a field; padding takes place only if the
  227.      specified field width exceeds the actual width.  Characters
  228.      generated by _p_r_i_n_t_f are printed as by _p_u_t_c(3S).
  229.  
  230. RREETTUURRNN VVAALLUUEE
  231.      Except for _s_p_r_i_n_t_f, _v_s_p_r_i_n_t_f, and _v_s_n_p_r_i_n_t_f, the functions
  232.      all return the number of characters printed, or -1 if an
  233.      error occurred.  _S_p_r_i_n_t_f, _v_s_p_r_i_n_t_f, and _v_s_n_p_r_i_n_t_f return a
  234.      pointer to the result string (the first argument).
  235.  
  236. EEXXAAMMPPLLEESS
  237.      To print a date and time in the form `Sunday, July 3,
  238.      10:02', where _w_e_e_k_d_a_y and _m_o_n_t_h are pointers to null-
  239.      terminated strings:
  240.  
  241.           printf("%s, %s %d, %02d:%02d", weekday, month, day,
  242.                hour, min);
  243.  
  244.      To print pi to 5 decimals:
  245.  
  246.           printf("pi = %.5f", 4*atan(1.0));
  247.  
  248. SSEEEE AALLSSOO
  249.      putc(3S), scanf(3S)
  250.  
  251. BBUUGGSS
  252.      The functions still supports %_D, %_O, and %_U.  Do not use
  253.      these formats, as they will be disappearing soon.
  254.  
  255.      For ANSI compatibility, the _s_p_r_i_n_t_f family should return the
  256.      number of characters printed, rather than the buffer string.
  257.  
  258.  
  259.  
  260.  
  261. Sprite v1.0             24 September 1990                       4
  262.  
  263.  
  264.  
  265.